import subprocess

def run_adb_command(command):
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, error = process.communicate()
    return output, error

def calculate_center(bounds):
    # 首先，根据 '][' 分割字符串
    x1_y1, x2_y2 = bounds[1:-1].split('][')

    # 然后，分别提取 x1, y1, x2, y2
    x1, y1 = map(int, x1_y1.split(','))
    x2, y2 = map(int, x2_y2.split(','))

    # 计算中心点坐标
    center_x = (x1 + x2) // 2
    center_y = (y1 + y2) // 2
    return center_x, center_y



# 计算 “法币交易” 按钮的点击坐标
button_bounds = "[257,2538][513,2590]"
click_x, click_y = calculate_center(button_bounds)

# 使用 ADB 命令模拟点击
run_adb_command(f"adb shell input tap {click_x} {click_y}")
